<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="ThemeBucket">
    <link rel="shortcut icon" href="#" type="image/png">
    
    <title>Form Layouts</title>
    <link href="/public/js/summernote/dist/summernote.css" rel="stylesheet">
    <!--multi-select-->
    <link rel="stylesheet" type="text/css" href="/public/js/jquery-multi-select/css/multi-select.css" />
    <!--tags input-->
    <link rel="stylesheet" type="text/css" href="/public/js/jquery-tags-input/jquery.tagsinput.css" />
    <script language="javascript">
        function RunOnBeforeUnload() {window.onbeforeunload = function(){ return ""; } }
    </script>
    <?php $this->load->view('library/header');?>
</head>

<body onload="RunOnBeforeUnload()" class="sticky-header">

<?php $this->load->view('library/left');?>

<!-- main content start-->
<div class="main-content" >
    
    <?php $this->load->view('library/top');?>
    
    <!-- page heading start-->
    <div class="page-heading">
        <h3>
            添加商品
        </h3>
        <ul class="breadcrumb">
            <li>
                <a href="#">Forms</a>
            </li>
            <li class="active"> Forms Layouts </li>
        </ul>
    </div>
    <!-- page heading end-->
    
    <!--body wrapper start-->
    <section class="wrapper">
        <div class="row">
            <div class="col-md-12">
                <!-- page start-->
                <section class="panel">
                    <header class="panel-heading custom-tab turquoise-tab">
                        <ul class="nav nav-tabs">
                            <li class="active">
                                <a href="#home2" data-toggle="tab">站点信息</a>
                            </li>
                        </ul>
                    </header>
                    <form id="commentForm" class="form-horizontal adminex-form" method="post">
                        <div class="panel-body">
                            <div class="tab-content">
                                <div class="tab-pane active" id="home2">
                                    <div class="form-group ">
                                        <label for="cname" class="control-label col-lg-2">title</label>
                                        <div class="col-lg-10">
                                            <input class=" form-control" value="<?php echo $res['title']?>" name="title" type="text" />
                                        </div>
                                    </div>
                                    <div class="form-group ">
                                        <label for="cname" class="control-label col-lg-2">Conditions</label>
                                        <div class="col-lg-10">
                                            <select class=" form-control" name="disjunctive" style="float: left;width: 150px;">
                                                <option <?php if($res['disjunctive'] == 2){ echo "selected";}?> value="2">任何条件</option>
                                                <option <?php if($res['disjunctive'] == 1){ echo "selected";}?> value="1">所有条件</option>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="form-group ">
                                        <label for="cname" class="control-label col-lg-2">类型</label>
                                        <?php foreach(json_decode($res['text'],true) as $k => $v){?>
                                            <div class="col-lg-10" <?php if($k > 0){echo 'style="margin-left: 16.7%"';}?>>
                                                <select class=" form-control" name="column[]" style="float: left;width: 150px;">
                                                    <option <?php if($v['column'] == 'title'){ echo "selected";}?> value="title">title</option>
                                                    <option <?php if($v['column'] == 'type'){ echo "selected";}?> value="type">type</option>
                                                    <option <?php if($v['column'] == 'vendor'){ echo "selected";}?> value="vendor">vendor</option>
                                                    <option <?php if($v['column'] == 'tag'){ echo "selected";}?> value="tag">tag</option>
                                                </select>
                                                <select class=" form-control" name="relation[]" style="width: 150px;float: left;">
                                                    <option <?php if($v['relation'] == 'equals'){ echo "selected";}?> value="equals">is equal to</option>
                                                </select>
                                                <input class=" form-control" value="<?php echo $v['condition']?>" name="condition[]" type="text" style="width: 150px;float: left;"/>
                                                <?php if($k > 0){?>
                                                    <span class="jianhao" style="float: left;font-size: 30px;">-</span>
                                                <?php }else{?>
                                                    <span class="jiahao" style="float: left;font-size: 30px;">+</span>
                                                <?php }?>
                                                
                                            </div>
                                        <?php }?>
                                    </div>
                                </div>
                                <div class="com"></div>
                                
                            </div>
                        </div>
                        <footer class="panel-footer">
                            <button type="submit" name="handle_type" value="0" class="btn btn-post pull-right btn-big">提交信息</button>
                            <ul class="nav nav-pills p-option"></ul>
                        </footer>
                    </form>
                </section>
                <!-- page end-->
            </div>
        </div>
    </section>
    <!--body wrapper end-->
    
    <!--footer section start-->
    <footer>
        2014 &copy; AdminEx by
    </footer>
    <!--footer section end-->


</div>
<!-- main content end-->
</section>

<?php $this->load->view('library/footer');?>

<!--编辑器-->
<script src="/public/js/summernote/dist/summernote.js"></script>
<script src="/public/js/summernote/dist/lang/summernote-zh-CN.js"></script>

<!--multi-select-->
<script type="text/javascript" src="/public/js/jquery-multi-select/js/jquery.multi-select.js"></script>
<script type="text/javascript" src="/public/js/jquery-multi-select/js/jquery.quicksearch.js"></script>
<script src="/public/js/multi-select-init.js"></script>

<!--tags input-->
<script src="/public/js/jquery-tags-input/jquery.tagsinput.js"></script>
<script src="/public/js/tagsinput-init.js"></script>

<script src="/public/js/nestable/jquery.nestable.js"></script>
<script src="/public/js/nestable-init.js"></script>

<!--common scripts for all pages-->
<script src="/public/js/scripts.js"></script>

<script>
$('.jiahao').click(function(){
    var res = '';
    res += '<div class="col-lg-10" style="margin-left: 16%;">'
        res += '<select class=" form-control" name="column[]" style="float: left;width: 150px;">'
            res += '<option value="title">title</option>'
            res += '<option value="type">type</option>'
            res += '<option value="vendor">vendor</option>'
            res += '<option value="tag">tag</option>'
        res += '</select>'
        res += '<select class=" form-control" name="relation[]" style="width: 150px;float: left;">'
            res += '<option value="equals">is equal to</option>'
        res += '</select>'
        res += '<input class=" form-control" name="condition[]" type="text" style="width: 150px;float: left;"/>'
        res += '<span class="jianhao" style="float: left;font-size: 30px;">-</span>'
    res += '</div>'
    $('.com').append(res);
})
$(document).on('click','.jianhao',function(){
    $(this).parent('.col-lg-10').remove();
})
    jQuery(document).ready(function(){
        
        $('#add_cate').click(function () {
            var cate_name = $('#cate_name').val();
            $('#cate_name').val('');
            if (cate_name) {
                $('#cate').append('<option value="'+cate_name+'">'+cate_name+'</option>');
            }
        });

        $('#summernote').summernote({
            tabsize: 2,
            height: 300,
            lang: 'zh-CN'
        });

        $('#commentForm').submit(function () {

            t = setTimeout(function() {
                $('.panel-footer .btn-big').attr('disabled','disabled').addClass('btn-submit-disabled').html('正在提交，请稍等...');
            }, 200);

            var data = new FormData(this);
            $("#cate option:not(:selected)").each(function (i) {
                var val = $(this).attr('value');
                if (val) {
                    data.append("cate[]", val);
                }
            });

            $.ajax({
                type: 'POST',
                url: '<?php echo base_url('siteweb/shopify_cat_save'. ($res['id'] ? "/id/{$res['id']}" : ''));?>',
                data: data,
                success: function (data) {
                    clearTimeout(t);
                    if (data.status != 'success') {
                        swal({
                            title: data.info,
                            text: '2秒后关闭',
                            type: data.status,
                            allowOutsideClick: false,
                            timer: 1500,
                            showConfirmButton: false
                        });
                        $('.panel-footer .btn-big').attr("disabled",false).removeClass('btn-submit-disabled').html('提交信息');
                    } else {
                        swal({
                            title: data.info,
                            text: '2秒后关闭',
                            type: data.status,
                            allowOutsideClick: false,
                            timer: data.stop ? data.stop : 1500,
                            showConfirmButton: false
                        }).then(function(isConfirm) {
                            window.onbeforeunload = '';
                            window.location.href = '<?php echo base_url('siteweb/shopify_cat_list');?>';
                        });
                        $('.panel-footer .btn-big').removeClass('btn-submit-disabled').html(data.info);
                    }

                },
                dataType:'json',
                cache: false,
                contentType: false,
                processData: false
            });

            return false;
        });
    });
</script>

</body>
</html>
